package train48days;

public class 求正数数组的最小组成和 {
    public int getFirstUnFormedNum(int[] arr) {
        int min = Integer.MAX_VALUE;
        int max = 0;
        for (int i :arr){
            min = Math.min(min,i);
            max+=i;
        }
        boolean[] result = new boolean[max+1];
        result[0] = true;
        for (int  o : arr){
            for (int j = max; j >=o;j--) {
                result[j] = result[j-o]||result[j];
            }
        }
        for (int j = min; j <result.length ; j++) {
            if (!result[j]){
                return j;
            }
        }
        return max+1;
    }
}
